import {
  getModelTree,
  modelPreview
} from './api.js'
export default {
  data() {
    return {
      viewToken: '',
      treeDataList: [],
      engineeringSectionId: '',
      elementTreeData: [],
      showModelTree: false,
      subSectionId: '',
      defaultTreeId: '',
      modelLoaded: false,
      fileId: '',
      showElementTreeTab: true
    }
  },
  mounted() {
    // 取消默认右键菜单行为
    document.addEventListener('contextmenu', function (event) {
      event.preventDefault()
    })
  },
  methods: {
    modelLoadedHandle() {
      this.modelLoaded = true
    },
    async getModelViewToken() {
      // 若无接口提供，屏蔽此处，使用bimface提供的默认构件树数据。
      this.getElementTreeData()
      const { data } = await modelPreview()
      this.viewToken = data || ''
    },
    // 构件树数据，可通过接口获取系统自定义的构件树数据，也可通过bimface提供的默认构件树数据
    async getElementTreeData(id, isDefault) {
      const { data } = await getModelTree({
        engineeringSectionId: this.engineeringSectionId,
        modelManageId: id
      })
      this.elementTreeData = data
      if (isDefault) {
        this.subSectionId = data[0].subSectionId
        this.defaultTreeId = data[0].id
      }
    },
    treeNodeClick(node) {
      this.subSectionId = node.data.subSectionId
    },
    modelClick(data, treeSelected) {
      this.subSectionId = data.subSectionId
      if (this.$refs.modelTree) {
        this.$refs.modelTree.setCurrentByModelClick(data, treeSelected)
      }
    }
  }
}
